/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.cef.variable.dtgenerator.vardtmGenerate.javageneratecmpcode;

import com.inspur.edp.cef.designtime.api.operation.CommonOperation;
import com.inspur.edp.cef.variable.dtgenerator.vardtmGenerate.JavaCompCodeNames;
import com.inspur.edp.das.commonmodel.entity.GspCommonModel;

public  class JavaCommonDeterminationGenerator extends JavaBaseCommonCompCodeGenerator {
  @Override
  protected String getBaseClassName(){
    return  JavaCompCodeNames.AbstractDeterminationClassName;
  }
  protected com.inspur.edp.das.commonmodel.entity.GspCommonModel GspCommonModel;

  public JavaCommonDeterminationGenerator(GspCommonModel GspCommonModel, CommonOperation operation, String nameSpace, String path)
  {
    super(GspCommonModel, operation, nameSpace, path);
    this.GspCommonModel = GspCommonModel;
  }

  @Override
  protected String GetNameSpaceSuffix()
  {
    return JavaCompCodeNames.VariableDeterminationNameSpaceSuffix;
  }

  @Override
  protected void GenerateExtendUsing(StringBuilder result)
  {

    ///#region using
    result.append(GetUsingStr(JavaCompCodeNames.DeterminationSpiNameSpace));
    result.append(GetUsingStr(JavaCompCodeNames.DeterminationApiNameSpace));
    result.append(GetUsingStr(JavaCompCodeNames.DeterminationChangeset));

    ///#endregion
  }

  @Override
  protected void JavaGenerateConstructor(StringBuilder result)
  {
    result.append(GetIndentationStr()).append(JavaCompCodeNames.KeywordPublic).append(" ").append(getCompName()).append("(IVarDeterminationContext context, IChangeDetail change)").append("{").append(getNewline());
    result.append(GetDoubleIndentationStr()).append("super((IVarDeterminationContext) context, change);").append(getNewline() );
    result.append(GetIndentationStr()).append("}").append(getNewline());
  }

  @Override
  protected void JavaGenerateExtendMethod(StringBuilder result)
  {
    if (this.isInterpretation)
    {
      JavaGenerateInterpretationVarExtendMethod(result);
    }
    else
    {
      JavaGenerateVarExtendMethod(result);
    }
  }

  protected final void JavaGenerateVarExtendMethod(StringBuilder result)
  {
    result.append(GetIndentationStr()).append(JavaCompCodeNames.KeywordPrivate).append(" ").append(GspCommonModel.getVariables().getGeneratedEntityClassInfo().getClassName()).append(" getData() ").append("{").append(getNewline());

    result.append(GetDoubleIndentationStr()).append(JavaCompCodeNames.KeywordReturn).append(" ").append("(").append(GspCommonModel.getVariables().getGeneratedEntityClassInfo().getClassName()).append(")").append("getContext().getData()").append(" ;").append(getNewline());
    result.append(GetIndentationStr()).append("}").append(getNewline());
  }

  protected final void JavaGenerateInterpretationVarExtendMethod(StringBuilder result)
  {
    result.append(GetIndentationStr()).append(JavaCompCodeNames.KeywordPrivate).append(" ").append(JavaCompCodeNames.ICefData).append(" getData() ").append("{").append(getNewline());

    result.append(GetDoubleIndentationStr()).append(JavaCompCodeNames.KeywordReturn).append(" ").append("(").append(JavaCompCodeNames.ICefData).append(")").append("getContext().getData()").append(" ;").append(getNewline());
    result.append(GetIndentationStr()).append("}").append(getNewline());
  }

  /**
   获取构件名称

   @return
   */
  @Override
  protected String GetInitializeCompName()
  {
    return String.format(operation.getCode(), "Determination");
  }
}
